package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import com.itheima.service.UserService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class UserServiceImpl implements UserService {
    private UserDao userDao;
    private String name;
    private int age;

    private String[] hobbies;
    private List<Integer> list;
    private Map<String, User> userMap;
    private Properties properties;

    public UserServiceImpl(UserDao userDao, String name) {
        this.userDao = userDao;
        this.name = name;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setHobbies(String[] hobbies) {
        this.hobbies = hobbies;
    }

    public void setList(List<Integer> list) {
        this.list = list;
    }

    public void setUserMap(Map<String, User> userMap) {
        this.userMap = userMap;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }
     public UserServiceImpl() {
        System.out.println("UserServiceImpl对象创建了");
    }

    //定义init初始化方法，会在bean对象创建完成之后执行
    public void init(){
        System.out.println("init method is running...");
    }

    @Override
    public void save() {
        System.out.println("UserServiceImpl的save方法执行了..."+name+","+age);
        //需要调用dao层方法，保存用户信息
        userDao.save();
    }

    //定义destroy销毁的方法，会在bean被释放之后执行
    public void destroy(){
        System.out.println("destroy method is running...");
    }

    @Override
    public String toString() {
        return "UserServiceImpl{" +
                "userDao=" + userDao +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", hobbies=" + Arrays.toString(hobbies) +
                ", list=" + list +
                ", userMap=" + userMap +
                ", properties=" + properties +
                '}';
    }
}
